<template>
  <div>
    <form @submit.prevent="login">
      <input type="text" v-model="username">
      <button>登录</button>
    </form>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  data(){
    return {
      username: ''
    }
  },
  methods:{
    async login(){
      const {data: res} = await this.$http.post('/login', {username: this.username})
      if(res.code === '20000'){
        localStorage.setItem('token', res.token)
        this.$router.push('/')
      }
    }
  }
}
</script>

<style>

</style>